sink("mturk.full.analysis-psrm-log.txt",append=F,type="output")

library(xtable)
library(plyr)

##
#Pilot Analysis
##
load('labeled.articles-psrm.RData')

###
#Distribution of Topics and Slant Ratings Among Labeled Articles
###

#Topic Ratings
article.rating.out <- subset(labeled.articles,labeled.articles$top.level!='Other')
article.rating.out$top.level[which(article.rating.out$top.level %in% c('Clinton','Trump'))] <- 'Scandal'
article.out.table <- ddply(article.rating.out,.(top.level),summarise,art.length=length(rating.scale))
article.out.table$proportion <- article.out.table$art.length/sum(article.out.table$art.length)
article.out.table <- article.out.table[order(article.out.table$proportion,decreasing=TRUE),]
xtable(article.out.table)

#Slant Ratings
article.rating.out <- subset(article.rating.out,!is.na(article.rating.out$rating.scale))
article.slant.out <- ddply(article.rating.out,.(rating.scale),summarise,art.length=length(rating.scale))
article.slant.out$proportion <- article.slant.out$art.length/sum(article.slant.out$art.length)
xtable(article.slant.out)

###
#Table B1 - Typical Slant Rating Does Not Vary by Coder's 2016 Vote Choice
###
code.comparison <- na.omit(ddply(labeled.articles,.(party),summarise,rating.scale=mean(rating.scale,na.rm=TRUE)))
code.comparison$party <- c('Voted Democratic','Voted 3rd Party/Did not vote','Voted Republican')
names(code.comparison) <- c('Presidential Vote in 2016','Average Article Rating')
xtable(code.comparison,caption="Article Rating by Political Views")
sink()